#ifndef SCREEN_WRITER_H
#define SCREEN_WRITER_H

#include <Ogre.h>
#include <OgreTextAreaOverlayElement.h>

#include <string>
#include <map>

class ScreenWriter : public Ogre::Singleton<ScreenWriter>
{
public:
	struct Entry
	{
		Entry()
		{
			x = 0;
			y = 0;
			size = 1.0f;
		}

		float x;
		float y;
		float size;

		std::string text;
	};

	typedef std::vector<Entry> Strings;

	ScreenWriter(int windowWidth = 800, int windowHeight = 600);
	~ScreenWriter();
	
	void init();
	void updateWindowExtents(int winWidth, int winHeight);
	
	void write(float x, float y, const char*, ...);
	void write(float x, float y, Ogre::String, ...);
	void write(float x, float y, float size, const char*, ...);
	void write(Entry& entry);

	void begin(float x, float y, float size);
	void write(const char*, ...);

	void removeVerticalAt(float x);

	void update();

	static ScreenWriter& getSingleton(void);
	static ScreenWriter* getSingletonPtr(void);

private:
	Strings texts;

	float defaultSize;

	int windowWidth;
	int windowHeight;

	Ogre::Overlay* overlay;
	Ogre::OverlayContainer* panel;

	enum { MAX_TEXT_AREAS = 50 };

	Ogre::TextAreaOverlayElement* textAreas[MAX_TEXT_AREAS];

	struct Context
	{
		Context();

		float x;
		float y;
		float size;
	} context;
};

#endif // SCREEN_WRITER_H
